package com.elitel.frame.main.config.serviceaccess;

import com.elitel.frame.main.config.serviceaccess.interceptor.GeneralInterceptor;
import com.elitel.frame.main.config.serviceaccess.interceptor.AppCodeInterceptor;
import com.elitel.frame.main.config.serviceaccess.interceptor.ParamRequireInterceptor;
import com.elitel.frame.main.config.serviceaccess.interceptor.ServiceStatusInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 服务访问控制配置类
 * @author hi_bj
 * @since 2023-10-17
 */
@Configuration
public class ServiceAccessConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        CustomServiceAccessInterceptor serviceAccessInterceptor = new CustomServiceAccessInterceptor();
        //添加通用验证，验证参数是否为空
        serviceAccessInterceptor.addInterceptor(new GeneralInterceptor());
        //添加服务发布状态验证
        serviceAccessInterceptor.addInterceptor(new ServiceStatusInterceptor());
        //添加AppCode授权码验证
        serviceAccessInterceptor.addInterceptor(new AppCodeInterceptor());
        //参数必填校验
        serviceAccessInterceptor.addInterceptor(new ParamRequireInterceptor());

        InterceptorRegistration registration = registry.addInterceptor(serviceAccessInterceptor);
        //拦截多表查询和SQL查询
        registration.addPathPatterns("/business/singleServer/querySingleTB");
        registration.addPathPatterns("/business/multipleServer/multipleTableServer");
        registration.addPathPatterns("/business/polymerServer/queryPolymerServer");
        registration.addPathPatterns("/business/fileServer/queryFileServer");
    }


}
